package com.ktg.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.ktgcommon.domain.mainData.MdClient;
import com.ktg.ktgcommon.domain.mainData.MdVendor;
import com.ktg.ktgcommon.filter.TokenVerifyFilter;
import com.ktg.ktgcommon.query.QueryVendor;
import com.ktg.mapper.ClientMapper;
import com.ktg.mapper.VendorManagerMapper;
import com.ktg.service.VendorManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class VendorManagerServiceImpl implements VendorManagerService {
    @Autowired
    private VendorManagerMapper vendorManagerMapper;

    @Override
    public Page<MdVendor> selectPage(Page<MdVendor> page, QueryVendor queryVendor) {
        Page<MdVendor> mdVendorPage = vendorManagerMapper.selectPage(page, queryVendor);
        return mdVendorPage;
    }

    @Override
    public MdVendor checkVendorById(Long vendorId) {
        MdVendor mdVendor = vendorManagerMapper.checkVendorById(vendorId);
        return mdVendor;
    }

    @Override
    public Integer AddOrChVendor(MdVendor mdVendor) {
        //解析jwt获取user信息
        TokenVerifyFilter tokenVerifyFilter = new TokenVerifyFilter();
        if (mdVendor.getVendorId() != null) {
            //设置更新时间
            mdVendor.setUpdateTime(new Date());
            //设置更新者名称
            mdVendor.setUpdateBy(tokenVerifyFilter.getUserName().getUsername());
            return vendorManagerMapper.changeMdVendor(mdVendor);
        } else {
            //设置创建时间
            mdVendor.setCreateTime(new Date());
            //设置创建者名称
            mdVendor.setCreateBy(tokenVerifyFilter.getUserName().getUsername());
            return vendorManagerMapper.addMdVendor(mdVendor);
        }

    }

    @Override
    public Integer delVendor(Long vendorId) {
        Integer integer = vendorManagerMapper.delVendor(vendorId);
        return integer;
    }

    @Override
    public Integer delVendorIdArray(List<Long> arrayVendorId) {
        Integer integer = vendorManagerMapper.delVendorIdArray(arrayVendorId);
        return integer;
    }
}
